"""
A Collection of simple plugins to use when testing
"""
__revision__ = "$Id: testplugins.py 26 2007-01-20 07:14:39Z jens.persson $"

from worde import plugins
from worde.model import Post

class Uppercase(plugins.Plugin):
    """
    change the case of the post into uppercase
    """
    def prerender(self, text):
        "-"
        return text.upper()
    def render(self, text, request):
        "-"
        return text.upper()

class Lowercase(plugins.Plugin):
    """
    change the case of the post into lowercase
    """
    def prerender(self, text):
        "-"
        return text.lower()
    def render(self, text, request):
        "-"
        return text.lower()


class Add_RemoteAddr(plugins.Plugin):
    """
    Add the Remote Address to all posts
    """
    def render(self, text, request):
        "-"
        return text + "<br />" + request.remote_addr


class Archive(plugins.Plugin):
    """
    Add the a list of all months with published posts
    """
    def sidebox(self, request):
        "-"
        #TODO: make dateformat configurable
        dates = [post.created.strftime("%B %Y") for post in Post.select()]
        seen = {}
        result = []
        for date in dates:
            if date in seen:
                continue
            seen[date] = 1
            result.append(date)

        # Ugly html building...
        return "<ol>\n  <li>" + "</li>\n  <li>".join(result) +"</li>\n</ol>"